package com.bw.home.widget;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.bw.home.R;
import com.bw.home.databinding.BottomdialogDanmuBinding;
import com.google.android.material.bottomsheet.BottomSheetDialog;

/**
 * @author:created by hahajing
 * 时间：2024/5/5 0005
 * 企鹅号:444511958
 * 描述:
 */
public class DanMuBottomDialog extends BottomSheetDialog {

    private DanMuCallback callback;

    public void setCallback(DanMuCallback callback) {
        this.callback = callback;
    }

    private com.bw.home.databinding.BottomdialogDanmuBinding bind;

    public DanMuBottomDialog(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public DanMuBottomDialog(@NonNull Context context, int theme) {
        super(context, theme);
        initView(context);
    }

    protected DanMuBottomDialog(@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView(context);
    }

    private void initView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.bottomdialog_danmu,null,false);
        bind = BottomdialogDanmuBinding.bind(view);
        setContentView(bind.getRoot());

        bind.tvBottomdialogDamuClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        bind.tvBottomdialogDamuSend.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                String content = bind.etBottomdialogDanmuContent.getText().toString().trim();
                if (TextUtils.isEmpty(content)){
                    Toast.makeText(v.getContext(),"请输入弹幕内容",Toast.LENGTH_SHORT).show();
                    return;
                }

                if (callback!=null){
                    callback.danmuCompleted(content);

                }
                //关闭this
                dismiss();
            }
        });
    }


    public interface DanMuCallback{
        void danmuCompleted(String content);
    }

}
